/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class SimpleGame2 extends BasicGame {
    Image plane = null;
    Image plane1 = null;
    Image shot = null;
    Image plane2 = null;
    Image plane3 = null;
    Image plane4 = null;
    Image plane5 = null;
    Image land = null;
    Image exp = null;
    Image puntero = null;
    float x = 400;
    float y = 300;
    float i = -10;
    float j = -10;
    float x2 = 400;
    float py = -200;
    float py2 = -150;
    float px1 = 100;
    float px2 = 200;
    float px3 = 300;
    float px4 = 400;
    float px5 = 500;
    float scale = 1;
    public SimpleGame2() {
        super("Slick2D Path2Glory - SlickBasicGame");
    }

    @Override
    public void init(GameContainer gc)
            throws SlickException {
        plane = new Image("src/serveis/plane.png");
        plane1 = new Image("src/serveis/plane2.png");
        plane2 = new Image("src/serveis/plane2.png");
        plane3 = new Image("src/serveis/plane2.png");
        plane4 = new Image("src/serveis/plane2.png");
        plane5 = new Image("src/serveis/plane2.png");
        land = new Image("src/serveis/fetch.jpg");
        exp = new Image("src/serveis/explosion.jpg");
         shot = new Image("src/serveis/shot.jpg");
        //puntero = new Image("src/serveis/shot.jpg");
    }

    @Override
    public void update(GameContainer gc, int delta)
            throws SlickException {
        Input input = gc.getInput();
        


        if (input.isKeyDown(Input.KEY_A)) {
            float hip = 0.4f * delta;
            float auxX = x;
            x -= hip;
            //y-= hip * Math.cos(Math.toRadians(rotation));
            if (x <= -30){
                x = auxX;
            }
        }

        if (input.isKeyDown(Input.KEY_D)) {
            float hip = 0.4f * delta;

            //float rotation = plane.getRotation();
            float auxX = x;

            x += hip;
            // y-= hip * Math.cos(Math.toRadians(rotation));
            if (700 <= x){
                x = auxX;
            }
        }

        if (input.isKeyDown(Input.KEY_W)) {
            float hip = 0.4f * delta;

            float rotation = plane.getRotation();
            float auxY = y;
            x += hip * Math.sin(Math.toRadians(rotation));
            y -= hip * Math.cos(Math.toRadians(rotation));
            if (y <= 0){
                y = auxY;
            }
        }
        if (input.isKeyDown(Input.KEY_S)) {
            float hip = 0.4f * delta;

            float rotation = plane.getRotation();
            float auxY = y;
            x -= hip * Math.sin(Math.toRadians(rotation));
            y += hip * Math.cos(Math.toRadians(rotation));
            if (500 <= y){
                y = auxY;
            }
        }

        if (input.isKeyDown(Input.KEY_2)) {
            scale += (scale >= 5.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth() / 2.0f * scale, plane.getHeight() / 2.0f * scale);
        }
        if (input.isKeyDown(Input.KEY_1)) {
            scale -= (scale <= 1.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth() / 2.0f * scale, plane.getHeight() / 2.0f * scale);
        }

        if (input.isKeyPressed(Input.KEY_SPACE)) {
  //          st = new Shoot(x, y);
            i = x;
            j = y;
            
        }
        if (input.isKeyPressed(Input.KEY_L)) {
            Shoot st = new Shoot(x+58, y);
        }

        py += (float) 2;
        py2 += (float) 2;
        j -= (float) 10;
        //st.setY(y-(float) 10);

        if (py > 600){
            py = -200;
            py2 = -150;
        }
    }

    public void render(GameContainer gc, Graphics g)
            throws SlickException {
        land.draw(0, 0);
        //new Image(st.getImg()).draw();
        plane1.draw(px1, py);
        plane2.draw(px2, py + 25);
        plane3.draw(px3, py2);
        plane4.draw(px4, py + 25);
        plane5.draw(px5, py);
        
//        this.shoot(i, j);       //i = ancho j = alto
        shot.draw(i+58,j);
        if (((py2 <= j && j <= py2+100) && (px3-50 <= i && i <= px3+50))) {
            exp.draw(px3+5, py+50);
            py2 = 1000;
            plane3.draw(px3, py2);

        }
        if (((py2 <= y && y <= py2+100) && (px3-50 <= x && x <= px3+50))) {
            exp.draw(x+5, y+50);
            py2 = 1000;
            plane.draw(px3, py2);
            y = 1000;
            plane.draw(x, y);
            
        } else {
            plane.draw(x, y);
        }

    }


    public static void main(String[] args)
            throws SlickException {
        AppGameContainer app = new AppGameContainer(new SimpleGame2());

        app.setDisplayMode(800, 600, false);
        app.start();
    }

//    public Image shoot(float exis, float ygrega) throws SlickException{
//        float XX = exis;
//        float YY = ygrega;
//        Image shoot = new Image("src/serveis/shot.jpg");
//        shoot.draw(XX + 58, YY);
//        return shoot;
//    }
}
